###############################################################################
# SuperLinks                                                                  #
# Copyright (c) 2000-2007 Greg Nolle (http://greg.nolle.co.uk)                #
###############################################################################
# This program is free software; you can redistribute it and/or modify it     #
# under the terms of the GNU General Public License as published by the Free  #
# Software Foundation; either version 2 of the License, or (at your option)   #
# any later version.                                                          #
#                                                                             #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       #
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   #
# more details.                                                               ##                                                                             #
# You should have received a copy of the GNU General Public License along     #
# with this program; if not, write to the Free Software Foundation, Inc.,     #
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                 #
###############################################################################
# ControlPanel/Output/ModifyLanguage.pm.pl -> ModifyLanguage module           #
###############################################################################
# DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING!                         #
###############################################################################
package Skin::CP::ModifyLanguage;

BEGIN { require "System.pm.pl"; import System qw($SYSTEM); }
BEGIN { require "General.pm.pl"; import General qw($GENERAL); }
require "Standard.pm.pl";

use HTML::Dialog;
use strict;

sub new {
  my ($class) = @_;
  my $self    = {};
  return bless ($self, $class);
}

sub DESTROY { }

###############################################################################
# show subroutine
sub show {
  my $self = shift;
  my %in = (input => undef, error => "", @_);

  #----------------------------------------------------------------------#
  # Printing page...                                                     #

  my $Dialog = HTML::Dialog->new();

  my @Keys = keys(%{ $in{'input'}->{'LANGUAGE'} });
     @Keys = sort {
       ref($in{'input'}->{'LANGUAGE'}->{$a}) cmp ref($in{'input'}->{'LANGUAGE'}->{$b})
       || $a cmp $b
     } @Keys;

  my $Body;
  
  for (my $h = 0; $h <= $#Keys; $h++) {
    my $key = $Keys[$h];
    
    if (ref($in{'input'}->{'LANGUAGE'}->{$key}) eq "HASH") {
      $Body .= $Dialog->TableHeader(titles => [{ title => $key, colspan => 2, align => "left" }]);
      
      foreach my $key2 (sort keys %{ $in{'input'}->{'LANGUAGE'}->{$key} }) {
        $Body .= $Dialog->FormTextBox(
          name      => "FORM_".$key."-".$key2,
          value     => $in{'input'}->{'LANGUAGE'}->{$key}->{$key2},
          subject   => $key2
        );
      }
    } else {
      $Body .= $Dialog->FormTextBox(
        name      => "FORM_".$key,
        value     => $in{'input'}->{'LANGUAGE'}->{$key},
        subject   => $key
      );
    }
  }

  $Body .= $Dialog->FormButton(
    items => [
      { type => "submit", value => "Modify" },
      { type => "reset", value => "Cancel" }
    ], join => "&nbsp;"
  );

  $Body = $Dialog->Table(body => $Body);
  $Body = $Dialog->StandardPage(
    body        => $Body,
    header      => "Modify a Language File",
    form        => 1,
    hiddens     => [
      { name => "Referer", value => $SL::QUERY{'Referer'} },
      { name => "LID", value => $in{'input'}->{'LANGUAGESET'}->{'ID'} },
      { name => "Language", value => $SL::QUERY{'Language'} },
      { name => "action", value => "DoModifyLanguage" },
      { name => "CP", value => "1" },
      { name => "SID", value => $SL::ADMIN{'SID'} }
    ]
  );
}

###############################################################################
# do subroutine
sub do {
  my $self = shift;
  my %in = (input => undef, @_);

  #----------------------------------------------------------------------#
  # Printing page...                                                     #

  my $Dialog = HTML::Dialog->new();

  return $Dialog->StandardPage(
    body    => qq~The language file has been updated.<p>Click <a href="$SYSTEM->{'SCRIPT_URL'}?CP=1&action=Languages&LID=$in{'input'}->{'LANGUAGESET'}->{'ID'}&SID=$SL::ADMIN{'SID'}">here</a> if you're not redirected in 5 seconds.~,
    header  => "Modify a Language File",
    metas   => [
      { http_equiv => "refresh", content => "5; url=$SYSTEM->{'SCRIPT_URL'}?CP=1&action=Languages&LID=$in{'input'}->{'LANGUAGESET'}->{'ID'}&SID=$SL::ADMIN{'SID'}" }
    ]
  );
}

1;